//
//  CHHTTPSessionRequset.m
//  音悦台
//
//  Created by qianfeng0 on 16/6/11.
//  Copyright © 2016年 changhao. All rights reserved.
//

#import "CHHTTPSessionRequset.h"
#import <AFHTTPSessionManager.h>

@interface CHHTTPSessionRequset ()

@property (nonatomic ,strong) AFHTTPSessionManager *manager;

@end

@implementation CHHTTPSessionRequset

+ (CHHTTPSessionRequset *)sharedManager {
    static CHHTTPSessionRequset *request = nil;
    if (!request) {
        request = [[CHHTTPSessionRequset alloc] init];
        request.manager = [[AFHTTPSessionManager alloc] init];
        NSMutableSet *set = [NSMutableSet setWithSet:request.manager.responseSerializer.acceptableContentTypes];
        [set addObject:@"text/html"];
        request.manager.responseSerializer.acceptableContentTypes = set;
    }
    return request;
}

- (void)GET:(NSString *)url pramas:(NSDictionary *)pramas success:(SUCCESS)success failure:(FAILURE)failure {
    [self.manager GET:url parameters:pramas progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        success(responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        failure(error);
    }];
}

- (void)POST:(NSString *)url pramas:(NSDictionary *)pramas success:(SUCCESS)success failure:(FAILURE)failure {
    [self.manager POST:url parameters:pramas constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        success(responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        failure(error);
    }];
}

@end
